package com.andy.beef.ui.main.adapter

import android.widget.TextView
import androidx.core.content.ContextCompat
import com.andy.beef.R
import com.andy.module.constant.TimePattern
import com.andy.beef.ui.main.bean.EnterInfoBean
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout


class EnterInfoListAdapter() : BaseQuickAdapter<EnterInfoBean, BaseViewHolder>(R.layout.main_adapter_enter_info_list) {

    init {
        addChildClickViewIds(R.id.content, R.id.btn_del)
    }

    override fun convert(holder: BaseViewHolder, item: EnterInfoBean) {
        val swipeMenuLayout = holder.getView<EasySwipeMenuLayout>(R.id.swipe_menu_layout)
        //没有计价可以删除
        swipeMenuLayout.isCanLeftSwipe = item.isCalculatePrice == 0
        swipeMenuLayout.isCanRightSwipe = item.isCalculatePrice == 0

        if (item.isCalculatePrice == 1) {
            holder.setText(R.id.tv_calculate_price_status, "已计价")
        } else {
            holder.setText(R.id.tv_calculate_price_status, "未计价")
        }

        holder.setText(R.id.tv_cow_number, context.getString(R.string.main_format_cattle_num, item.earTagNo))
        val tvStatus = holder.getView<TextView>(R.id.tv_check_status)
        holder.setText(R.id.tv_check_status, item.quarantineStatusDesc)
        initQuarantineStatus(tvStatus, item.quarantineStatus)
        holder.setText(R.id.tv_category, context.getString(R.string.main_format_brand_type, item.breedDesc))
        val date = TimeUtils.millis2String(item.entryTime, TimePattern.YYYY_MM_DD_HH_MM_CHINA)
        holder.setText(R.id.tv_date, context.getString(R.string.main_format_enter_time, date))
        holder.setText(R.id.tv_contact_name, context.getString(R.string.main_format_contact_people, item.contactName))
        holder.setText(R.id.tv_contact_phone, context.getString(R.string.main_format_contact_phone, item.contactPhone))
        holder.setVisible(R.id.line_view, holder.adapterPosition != itemCount - 1)

    }

    companion object {
        val QUARANTINE_STATUS_WAITING = 0
        val QUARANTINE_STATUS_PASS = 1
        val QUARANTINE_STATUS_ABNORMAL = 2
        var QUARANTINE_STATUS_ADD = 5
        fun initQuarantineStatus(tv: TextView, status: Int) {
            when (status) {
                QUARANTINE_STATUS_WAITING -> {
                    tv.setTextColor(ContextCompat.getColor(tv.context, R.color.color_c1))
                    tv.setBackgroundResource(R.drawable.shape_stroke_c1_4dp)
                }
                QUARANTINE_STATUS_PASS -> {
                    tv.setTextColor(ContextCompat.getColor(tv.context, R.color.color_c3))
                    tv.setBackgroundResource(R.drawable.shape_stroke_c3_4dp)
                }
                QUARANTINE_STATUS_ABNORMAL -> {
                    tv.setTextColor(ContextCompat.getColor(tv.context, R.color.color_c2))
                    tv.setBackgroundResource(R.drawable.shape_stroke_c2_4dp)
                }
            }
        }
    }
}



